#pragma once
#include "TypeDefinitions.h"
#include <fstream>
class ImageComparator
{
public:
	ImageComparator() //:
//		filee("file.txt")
	{}
//	std::ofstream filee;
	double compare (Image* first, Image* second)      //static????
	{
		double diff = 0;
		for(int i=0; i <width; i++)
		{
			for(int j=0; j < height; j++)
			{
				double r, g, b;
				r= (int)((*first)(i,j,0,0)) - (int)((*second)(i,j,0,0));
				g = (int)((*first)(i,j,0,1)) - (int)((*second)(i,j,0,1));
				b = (int)((*first)(i,j,0,2)) - (int)((*second)(i,j,0,2));
				diff += r*r + g*g + b*b;
			}
		}

		return diff;
	}

	double compareFragment(Image* first, Image* second, int leftUpX, int leftUpY, int rightBottomX, int rightBottomY)  //static??
	{
		double diff = 0;
		for(int i=leftUpX; i <=rightBottomX; i++)
		{
			for(int j=leftUpY; j <= rightBottomY; j++)
			{
		//		filee<<"I: "<<i<<" J: "<<j<<std::endl;
				double r, g, b;
				r= ((int)(*first)(i,j,0,0)) - (int)((*second)(i,j,0,0));
				g = ((int)(*first)(i,j,0,1)) - (int)((*second)(i,j,0,1));
				b = ((int)(*first)(i,j,0,2)) - (int)((*second)(i,j,0,2));
				diff += r*r + g*g + b*b;
			}
		}

		return diff;
	}
//	double compareSFML(sf::RenderTexture& texture, sf::Image& originalImage);

private:

};





/*
double ImageComparator::compareSFML(sf::RenderTexture& texture, sf::Image& originalImage)
{

	texture.display();
	sf::Image& generatedImage = texture.getTexture().copyToImage();


	double fitnessSFML = 0;
	for(int j = 0; j<height; j++)
	{
		for(int i = 0; i<width; i++)
		{

			double r = generatedImage.getPixel(j,i).r - originalImage.getPixel(j,i).r ;
			double g = generatedImage.getPixel(j,i).g - originalImage.getPixel(j,i).g ;
			double b = generatedImage.getPixel(j,i).b - originalImage.getPixel(j,i).b;
			fitnessSFML += r*r + g*g + b*b;
		}
	}

	return fitnessSFML;
}
*/
